class Solution {
    public int numberOfArithmeticSlices(int[] nums) {
        // 判断数组的长度是否大于3
        int n = nums.length;
        if (n < 3) {
            return 0;
        }

        // 创建 dp 表、初始化、填表、返回值
        int[] dp = new int[n];

        dp[0] = dp[1] = 0;

        for (int i = 2; i < n; i++) {
            int a = nums[i-2], b = nums[i-1], c = nums[i];
            dp[i] = c-b == b-a ? dp[i-1]+1 : 0;
        }

        int ret = 0;
        for (int i = 0; i < n; i++) {
            ret += dp[i];
        }

        return ret;
    }
}